package com.chinaisafe.user.controller;

import com.chinaisafe.base.common.validated.UpdateGroup;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.chinaisafe.base.common.annotation.OperationLog;
import com.chinaisafe.base.common.enums.BusinessTypeEnum;
import com.chinaisafe.base.common.vo.Answer;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.chinaisafe.user.vo.request.SysModuleReqVO;
import com.chinaisafe.user.vo.response.SysModuleRespVO;
import org.springframework.validation.annotation.Validated;
import com.chinaisafe.user.service.SysModuleService;
import org.springframework.web.bind.annotation.RestController;
import com.chinaisafe.base.common.validated.AddGroup;
/**
 * SysModuleController
 * Description：系统资源模块接口层
 *
 * @author xuefu.shu
 * @date  2024-07-12 16:06:57
 */
@RestController
@RequestMapping("/sysModule")
@Tag(name = "系统资源模块接口层", description = "系统资源模块接口层")
public class SysModuleController {

    @Autowired
    private SysModuleService sysModuleService;

    @GetMapping("/pageList")
    @Operation(summary = "获取系统资源模块分页列表", description = "获取系统资源模块分页列表")
    public Answer<IPage<SysModuleRespVO>> pageList(SysModuleReqVO sysModuleReqVO) {
        IPage<SysModuleRespVO> pageList = sysModuleService.getPageList(sysModuleReqVO);
        return Answer.success("获取成功", pageList);
    }

    @PostMapping()
    @Operation(summary = "新增系统资源模块", description = "新增系统资源模块")
    @OperationLog(title = "系统资源模块-新增", businessType = BusinessTypeEnum.INSERT)
    public Answer<SysModuleRespVO> add(@RequestBody @Validated(AddGroup.class) SysModuleReqVO sysModuleReqVO) {
        SysModuleRespVO sysModuleRespVO = sysModuleService.add(sysModuleReqVO);
        return Answer.success("保存成功", sysModuleRespVO);
    }

    @PutMapping()
    @Operation(summary = "根据id编辑系统资源模块", description = "根据id编辑系统资源模块")
    @OperationLog(title = "系统资源模块-根据id编辑", businessType = BusinessTypeEnum.UPDATE)
    public Answer<SysModuleRespVO> update(@RequestBody @Validated(UpdateGroup.class) SysModuleReqVO sysModuleReqVO) {
        SysModuleRespVO sysModuleRespVO = sysModuleService.update(sysModuleReqVO);
        return Answer.success("修改成功", sysModuleRespVO);
    }

    @GetMapping("/{sysModuleId}")
    @Operation(summary = "根据id获取系统资源模块", description = "根据id获取系统资源模块")
    public Answer<SysModuleRespVO> getDetailById(@PathVariable Long sysModuleId) {
        SysModuleRespVO sysModuleRespVO = sysModuleService.getDetailById(sysModuleId);
        return Answer.success("获取成功", sysModuleRespVO);
    }

    @DeleteMapping()
    @Operation(summary = "根据id删除系统资源模块", description = "根据id删除系统资源模块")
    @OperationLog(title = "系统资源模块-根据id删除", businessType = BusinessTypeEnum.DELETE)
    public Answer<Void> deleteByIds(@RequestParam("ids") Long[] ids) {
        sysModuleService.deleteByIds(ids);
        return Answer.success("删除成功");
    }

    /*@PostMapping("enableSwitch")
    @Operation(summary = "模块启用/禁用", description = "参数请放在?后面")
    public Answer<Void> enableSwitch(Long id) {
        sysModuleService.enableSwitch(id);
        return Answer.success("操作成功");
    }*/
}

